package com.chx.rpc02;

import com.chx.dto.User;

import java.io.*;
import java.net.Socket;

public class Stub {

    public static User getUser(int id) throws IOException {
        Socket socket=new Socket("localhost",8080);
        OutputStream os = socket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeInt(id);
        dos.flush();
        InputStream is = socket.getInputStream();
        DataInputStream dis=new DataInputStream(is);
        User user = new User(dis.readInt(), dis.readUTF());

        dis.close();
        dos.close();
        socket.close();
        return user;
    }

}
